package edu.cuit.svsp.controller;

import edu.cuit.svsp.request.ResponseResult;
import edu.cuit.svsp.service.FollowService;
import edu.cuit.svsp.util.JWTUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @className: FollowController
 * @author: pjy
 * @description: 关注控制器
 * @date: 2024/7/6
 */
@Slf4j
@RestController
@RequestMapping("/follow")
public class FollowController {
    @Resource
    private FollowService followService;

    // 更新关注
    @GetMapping("/update/{isFollow}/{fid}")
    public ResponseResult updateFollow(@PathVariable("isFollow") boolean isFollow, @PathVariable("fid") Integer fid, HttpServletRequest request){
        int uid = JWTUtil.getuid(request.getHeader("Authorization"));
        return new ResponseResult(HttpStatus.OK.value(), "success", followService.updateFollow(isFollow, fid, uid));
    }
    // 查关注
    @GetMapping("/findFid/{fid}")
    public ResponseResult findFollow(@PathVariable("fid") Integer fid, HttpServletRequest request){
        int uid = JWTUtil.getuid(request.getHeader("Authorization"));
        boolean follow = followService.findFollow(fid, uid);
        return new ResponseResult(HttpStatus.OK.value(), "success", follow);
    }
}
